from django.conf import settings
from django.core.files.storage import Storage

"""
自定义文件存储类:
1, 定义类继承自Storage
2, 必须保证参数能够初始化
3, 必须实现open,save方法

"""


class MyStorage(Storage):
    def __init__(self, fdfs_base_url=None):
        self.fdfs_base_url = fdfs_base_url or settings.FDFS_BASE_URL

    def open(self, name, mode='rb'):
        """打开文件调用"""
        pass

    def save(self, name, content, max_length=None):
        """保存文件调用"""
        pass

    def exists(self, name):
        """上传的时候判断图片是否存在了"""
        pass

    def size(self, name):
        """获取文件大小"""
        pass

    def url(self, name):
        """返回图片的url地址"""
        return self.fdfs_base_url + name
